<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of netinit</title>
  <meta name="keywords" content="netinit">
  <meta name="description" content="NETINIT Initialise the weights in a network.">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html &copy; 2003 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../../m2html.css">
</head>
<body>
<a name="_top"></a>
<div><a href="../../menu.html">Home</a> &gt;  <a href="#">ReBEL-0.2.7</a> &gt; <a href="#">netlab</a> &gt; netinit.m</div>

<!--<table width="100%"><tr><td align="left"><a href="../../menu.html"><img alt="<" border="0" src="../../left.png">&nbsp;Master index</a></td>
<td align="right"><a href="menu.html">Index for .\ReBEL-0.2.7\netlab&nbsp;<img alt=">" border="0" src="../../right.png"></a></td></tr></table>-->

<h1>netinit
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>NETINIT Initialise the weights in a network.</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>function net = netinit(net, prior) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre class="comment">NETINIT Initialise the weights in a network.

    Description

    NET = NETINIT(NET, PRIOR) takes a network data structure NET and sets
    the weights and biases by sampling from a Gaussian distribution. If
    PRIOR is a scalar, then all of the parameters (weights and biases)
    are sampled from a single isotropic Gaussian with inverse variance
    equal to PRIOR. If PRIOR is a data structure of the kind generated by
    MLPPRIOR, then the parameters are sampled from multiple Gaussians
    according to their groupings (defined by the INDEX field) with
    corresponding variances (defined by the ALPHA field).

    See also
    <a href="mlpprior.html" class="code" title="function prior = mlpprior(nin, nhidden, nout, aw1, ab1, aw2, ab2)">MLPPRIOR</a>, <a href="netunpak.html" class="code" title="function net = netunpak(net, w)">NETUNPAK</a>, <a href="rbfprior.html" class="code" title="function [mask, prior] = rbfprior(rbfunc, nin, nhidden, nout, aw2, ab2)">RBFPRIOR</a></pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="netunpak.html" class="code" title="function net = netunpak(net, w)">netunpak</a>	NETUNPAK Separates weights vector into weight and bias matrices.</li></ul>
This function is called by:
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="demev3.html" class="code" title="">demev3</a>	DEMEV3	Demonstrate Bayesian regression for the RBF.</li></ul>
<!-- crossreference -->


<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function net = netinit(net, prior)</a>
0002 <span class="comment">%NETINIT Initialise the weights in a network.</span>
0003 <span class="comment">%</span>
0004 <span class="comment">%    Description</span>
0005 <span class="comment">%</span>
0006 <span class="comment">%    NET = NETINIT(NET, PRIOR) takes a network data structure NET and sets</span>
0007 <span class="comment">%    the weights and biases by sampling from a Gaussian distribution. If</span>
0008 <span class="comment">%    PRIOR is a scalar, then all of the parameters (weights and biases)</span>
0009 <span class="comment">%    are sampled from a single isotropic Gaussian with inverse variance</span>
0010 <span class="comment">%    equal to PRIOR. If PRIOR is a data structure of the kind generated by</span>
0011 <span class="comment">%    MLPPRIOR, then the parameters are sampled from multiple Gaussians</span>
0012 <span class="comment">%    according to their groupings (defined by the INDEX field) with</span>
0013 <span class="comment">%    corresponding variances (defined by the ALPHA field).</span>
0014 <span class="comment">%</span>
0015 <span class="comment">%    See also</span>
0016 <span class="comment">%    MLPPRIOR, NETUNPAK, RBFPRIOR</span>
0017 <span class="comment">%</span>
0018 
0019 <span class="comment">%    Copyright (c) Ian T Nabney (1996-2001)</span>
0020 
0021 <span class="keyword">if</span> isstruct(prior)
0022     <span class="keyword">if</span> (isfield(net, <span class="string">'mask'</span>))
0023     <span class="keyword">if</span> find(sum(prior.index, 2)) ~= find(net.mask)
0024         error(<span class="string">'Index does not match mask'</span>);
0025     <span class="keyword">end</span>
0026     sig = sqrt(prior.index*prior.alpha);
0027     <span class="comment">% Weights corresponding to zeros in mask will not be used anyway</span>
0028     <span class="comment">% Set their priors to one to avoid division by zero</span>
0029     sig = sig + (sig == 0);  
0030     sig = 1./sqrt(sig);
0031     <span class="keyword">else</span>
0032     sig = 1./sqrt(prior.index*prior.alpha);
0033     <span class="keyword">end</span>
0034     w = sig'.*randn(1, net.nwts); 
0035 <span class="keyword">elseif</span> size(prior) == [1 1]
0036   w = randn(1, net.nwts).*sqrt(1/prior);
0037 <span class="keyword">else</span>
0038   error(<span class="string">'prior must be a scalar or a structure'</span>);
0039 <span class="keyword">end</span>  
0040 
0041 <span class="keyword">if</span> (isfield(net, <span class="string">'mask'</span>))
0042     w = w(logical(net.mask));
0043 <span class="keyword">end</span>
0044 net = <a href="netunpak.html" class="code" title="function net = netunpak(net, w)">netunpak</a>(net, w);
0045</pre></div>
<hr><address>Generated on Tue 26-Sep-2006 10:36:21 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/">m2html</a></strong> &copy; 2003</address>
</body>
</html>